/* #include <bits/stdc++.h> */
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p)
{
    return os << '(' << p.first << ", " << p.second << ')';
}
template<typename C,typename D = typename enable_if <!is_same<C, string>::value,typename C::value_type>::type>
ostream &operator<<(ostream &os, const C &v)
{
    os << '{';
    string sep;
    for (const D &x : v)
        os << sep << x, sep = ", ";
    return os << '}';
}

void dbg_out()
{
    cerr << endl;
}
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T)
{
    cerr << ' ' << H;
    dbg_out(T...);
}
#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

int ____________________CYCLE____________________;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define inf INT32_MAX
#define i64 int64_t
const int N = 1e5;

void solve(int cycle);

int main(){
#ifndef ONLINE_JUDGE
    freopen(".\\in.txt","r",stdin);
    freopen(".\\out.txt","w",stdout);
#endif
    ios::sync_with_stdio(false);
    std::cin.tie(0);


    /* int _=1;
    cin >> _;
    //cout << "Case #" << _ << ": " << endl;
    for(____________________CYCLE____________________=1;____________________CYCLE____________________<=_;____________________CYCLE____________________++){
        //cout << ____________________CYCLE____________________ << ":\n";
        solve(____________________CYCLE____________________);
    } */

    solve(1);
    
}
int n,m;
const int dx[] = {0,1,0,-1};
const int dy[] = {1,0,-1,0};
char mapInfo[105][105];
int vis[105][105];
void dfs(int x,int y,char now){
    if(x < 1 || x > n || y < 1 || y > m) return;
    if(mapInfo[x][y] == now && vis[x][y] == 0){
        vis[x][y] = 1;
        rep(i,0,3){
            int nx = x + dx[i];
            int ny = y + dy[i];
            dfs(nx,ny,now);
        }
    }
}
void solve(int cycle){
    cin >> n >> m;
    if(n == 0 && m == 0) exit(0);
    memset(vis,0,sizeof(vis));
    rep(i,1,n){
        rep(j,1,m) cin >> mapInfo[i][j];
    }
    int cnt = 0;
    rep(i,1,n){
        rep(j,1,m){
            if(vis[i][j] == 0){
                dfs(i,j,mapInfo[i][j]);
                cnt++;
            }
        }
    }
    cout << cnt << endl;
}